Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic multi-partition GroupBy support to cuDF-Polars #17503

Merged
merged 35 commits into from
Mar 11, 2025

Conversation

rjzamora
Copy link
Member

@rjzamora rjzamora commented Dec 4, 2024

Description

Adds multi-partition support for simple GroupBy aggregations (following the same design as #17441)

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@rjzamora rjzamora added feature request New feature or request 2 - In Progress Currently a work in progress non-breaking Non-breaking change cudf.pandas Issues specific to cudf.pandas labels Dec 4, 2024
@rjzamora rjzamora self-assigned this Dec 4, 2024
Copy link

copy-pr-bot bot commented Dec 4, 2024

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions bot added Python Affects Python cuDF API. cudf.polars Issues specific to cudf.polars and removed cudf.pandas Issues specific to cudf.pandas labels Dec 4, 2024
@rjzamora
Copy link
Member Author

rjzamora commented Dec 4, 2024

/ok to test

Comment on lines 62 to 66
# Check that we are grouping on element-wise
# keys (is this already guaranteed?)
for ne in ir.keys:
if not isinstance(ne.value, Col): # pragma: no cover
return _single_fallback(ir, children, partition_info)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by elementwise keys? It's certainly not the case that we always group on columns. But I think it is the case that the group keys (if expressions) are trivially elementwise (e.g. a + b as a key is fine, but a.unique() or a.sort() is not)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I'm being extra cautious by requiring the keys to be Col. This comment is essentially asking: "can we drop this check altogether? ie. Will the keys always be element-wise?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so, yes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened pola-rs/polars#20152 as well

@rjzamora rjzamora marked this pull request as ready for review December 6, 2024 04:22
@rjzamora rjzamora requested a review from a team as a code owner December 6, 2024 04:22
@rjzamora
Copy link
Member Author

This PR is pretty-much "ready" - I don't think it makes sense to build more groupby logic directly on top of this. It would be much better to revise the underlying GroupBy class to make decomposition easier. However, it seems valuable to have basic groupby support available for testing/benchmarking before we have time to prioritize a larger GroupBy revision.

@rjzamora rjzamora added 3 - Ready for Review Ready for review by team and removed 2 - In Progress Currently a work in progress labels Mar 3, 2025
@rjzamora
Copy link
Member Author

rjzamora commented Mar 3, 2025

@wence- I'm marking this as "ready for review". As we discussed offline, this will need to be revised for general support. However, the current design should be sufficient for basic TPCH support/testing.

.items()
if c in groupby_key_columns
}
if cardinality_factor:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "cardinality factor" logic is new, and can be pulled out of the PR if necessary. However, we do need a mechanism to trigger shuffle-based groupby aggregations in practice.

@rjzamora
Copy link
Member Author

@wence- Any action items left for this PR?

Copy link
Contributor

@wence- wence- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Rick, I think this is looking pretty good. I have some suggestions for some cleanup, and one worry about the schemas we're using.

ir.schema,
ir.keys,
piecewise_exprs,
ir.maintain_order,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can support maintain_order == True (at least easily). So perhaps we should raise in that case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we support it for the tree reduction, but not for a shuffle-based reduction, right? The tree-reduction tasks should be ordered appropriately.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah true.

@rjzamora
Copy link
Member Author

Thanks for the review @wence- !

I tried addressing your comments - but I suppose I had to rewrite most of the code in the process.

Copy link
Contributor

@wence- wence- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nits, thanks for the iteration here Rick!

ir.schema,
ir.keys,
piecewise_exprs,
ir.maintain_order,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah true.

@rjzamora rjzamora added 5 - Ready to Merge Testing and reviews complete, ready to merge and removed 3 - Ready for Review Ready for review by team labels Mar 11, 2025
@rjzamora
Copy link
Member Author

/merge

@rapids-bot rapids-bot bot merged commit bd6e31c into rapidsai:branch-25.04 Mar 11, 2025
126 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in cuDF Python Mar 11, 2025
@rjzamora rjzamora deleted the cudf-polars-multi-groupby branch March 11, 2025 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to Merge Testing and reviews complete, ready to merge cudf.polars Issues specific to cudf.polars feature request New feature or request non-breaking Non-breaking change Python Affects Python cuDF API.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants